package org.desktop.web.client.custom.widget;

import org.desktop.web.client.custom.widget.DesktopFolder.Icon;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.resources.client.ClientBundle.Source;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.sencha.gxt.core.client.XTemplates;
import com.sencha.gxt.core.client.resources.StyleInjectorHelper;

public class DesktopFolderDefaultAppearance implements DesktopFolder.Appearance {

	
	public interface DesktopFolderStyle extends CssResource {

		String folderDesktop();

		String folderImgBig();
		
		String desktopBackground();

		// String folderMouseOver();
		//
		// String folderMouseOut();
	}

	public interface Resources extends ClientBundle {

		@Source("org/desktop/web/client/templates/css/desktopFolder.css")
		DesktopFolderStyle desktopFolderStyle();

		@Source("org/desktop/web/client/images/folder.gif")
		ImageResource folderImg();

		@Source("org/desktop/web/client/images/timesheet.gif")
		ImageResource timesheetImg();
		
		@Source("org/desktop/web/client/images/projects_icon.gif")
		ImageResource projects();
		
		@Source("org/desktop/web/client/images/roles.gif")
		ImageResource roles();


		@Source("org/desktop/web/client/images/users-icon.gif")
		ImageResource users();

	}

	public interface DesktopTemplate extends XTemplates {
		@XTemplate(source = "org/desktop/web/client/templates/html/bigFolder.html")
		SafeHtml template(DesktopFolderStyle style, ImageResource img,String text);

	}

	private Resources resources;
	private DesktopFolderStyle style;
	private DesktopTemplate template;
	private Icon icon;

	public DesktopFolderDefaultAppearance() {
		this(GWT.<Resources> create(Resources.class), GWT
				.<DesktopTemplate> create(DesktopTemplate.class));
	}

	public DesktopFolderDefaultAppearance(Resources resources,
			DesktopTemplate template) {
		this.resources = resources;
		this.style = resources.desktopFolderStyle();
		this.template = template;
		this.icon = icon;

		StyleInjectorHelper.ensureInjected(this.style, true);
	}

	@Override
	public void render(SafeHtmlBuilder builder,Icon icon,String text) {
		SafeHtml html = null;

		switch (icon) {
		case FOLDER:
			html = template.template(style, resources.folderImg(),text);
			break;
		case TIMESHEET:
			html = template.template(style, resources.timesheetImg(),text);
			break;
		case USERS:
			html = template.template(style, resources.users(),text);
			break;
		case PROJECTS:
			html = template.template(style, resources.projects(),text);
			break;
		case ROLES:
			html = template.template(style, resources.roles(),text);
			break;
		}

		builder.append(html);

	}

}
